package com.app.repository.impl;

import com.app.model.main.CommentsOfArticle;
import com.app.repository.interfaces.CommentsOfArticleMapper;
import com.app.support.dao.MybatisDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lichaojie on 2017/3/12. It's a beautiful day.
 */
@Repository
public class CommentsOfArticleMapperImpl implements CommentsOfArticleMapper {

    @Autowired
    private MybatisDao mybatisDao;

    @Override
    public int deleteByPrimaryKey(Long id){
        return mybatisDao.delete("com.app.dao.main.CommentsOfArticleMapper",".deleteByPrimaryKey",id);
    }

    @Override
    public int insert(CommentsOfArticle record){
        return mybatisDao.insert("com.app.dao.main.CommentsOfArticleMapper", ".insert", record);
    }

    @Override
    public int insertSelective(CommentsOfArticle record){
        return mybatisDao.insert("com.app.dao.main.CommentsOfArticleMapper", ".insertSelective", record);
    }

    @Override
    public CommentsOfArticle selectByPrimaryKey(Long id){
        return mybatisDao.get("com.app.dao.main.CommentsOfArticleMapper", ".selectByPrimaryKey", id);
    }

    @Override
    public CommentsOfArticle selectByParam(long userId, String time){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("time",time);
        return mybatisDao.get("com.app.dao.main.CommentsOfArticleMapper",".selectByParam",map);
    }

    @Override
    public int updateByPrimaryKeySelective(CommentsOfArticle record){
        return mybatisDao.update("com.app.dao.main.CommentsOfArticleMapper", ".updateByPrimaryKeySelective", record);
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(CommentsOfArticle record){
        return mybatisDao.update("com.app.dao.main.CommentsOfArticleMapper", ".updateByPrimaryKeyWithBLOBs", record);
    }

    @Override
    public int updateByPrimaryKey(CommentsOfArticle record){
        return mybatisDao.update("com.app.dao.main.CommentsOfArticleMapper",".updateByPrimaryKey",record);
    }

    @Override
    public long getCommentsNumber(long articleId){
        return mybatisDao.count("com.app.dao.main.CommentsOfArticleMapper", ".getCommentsNumber", articleId);
    }

    @Override
    public List<CommentsOfArticle> getListOrderedByIdDESC(long articleId, long lastId, int page, int number){
        Map<String,Object> map = new HashMap<>();
        map.put("articleId",articleId);
        map.put("lastId",lastId);
        return mybatisDao.getList("com.app.dao.main.CommentsOfArticleMapper",".getListOrderedByIdDESC",map,new RowBounds(0,number));
    }

    @Override
    public List<CommentsOfArticle> getListOrderedByIdASC(long articleId, long lastId, int page, int number){
        Map<String,Object> map = new HashMap<>();
        map.put("articleId",articleId);
        map.put("lastId",lastId);
        return mybatisDao.getList("com.app.dao.main.CommentsOfArticleMapper",".getListOrderedByIdASC",map,new RowBounds(0,number));
    }

    @Override
    public long getMaxId(){
        return mybatisDao.count("com.app.dao.main.CommentsOfArticleMapper",".getMaxId",null);
    }

    @Override
    public List<CommentsOfArticle> getListByUserIdBetween(long userId, String time1, String time2){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("time1",time1);
        map.put("time2",time2);
        return mybatisDao.getList("com.app.dao.main.CommentsOfArticleMapper",".getListByUserIdBetween",map);
    }

    @Override
    public List<CommentsOfArticle> getListByUserId(long userId){
        return mybatisDao.getList("com.app.dao.main.CommentsOfArticleMapper",".getListByUserId",userId);
    }
}
